import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { StudentService } from './student.service';
import { CreateStudentDto } from './dto/create-student.dto';
import { UpdateStudentDto } from './dto/update-student.dto';
import { Result } from '../common/dto/common.result';
import { PageStudentDto } from './dto/page-student.dto';

@Controller('student')
export class StudentController {
  constructor(private readonly studentService: StudentService) {
  }

  @Post('save')
  async create(@Body() createStudentDto: CreateStudentDto) {
    await this.studentService.create(createStudentDto);
    return Result.success();
  }

  @Get('list')
  async findAll() {
    return Result.successData(await this.studentService.findAll());
  }

  @Get('/info/:id')
  async findOne(@Param('id') id: number) {
    return Result.successData(await this.studentService.findOne(id));
  }

  @Patch('/info')
  async update(@Body() updateStudentDto: UpdateStudentDto) {
    await this.studentService.update(updateStudentDto.id, updateStudentDto);
    return Result.success();
  }

  @Delete('/info/:id')
  async remove(@Param('id') id: number) {
    await this.studentService.remove(id);
    return Result.success();
  }

  @Get('/list/page')
  async page(@Query() pageStudentDto: PageStudentDto) {
    const data = await this.studentService.page(pageStudentDto);
    return Result.successData(data);
  }
}
